package com.sdry.web.controller.zc.quality;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.lqy.LqyDailyEntity;
import com.sdry.model.zc.ZcDailyEntity;
import com.sdry.model.zc.ZcQueryCriteria;
import com.sdry.service.zc.ZcDailyService;
import com.sdry.utils.ResponseUtil;

/**
 * 
 * @ClassName:    ZcDailyController   
 * @Description:  质检日报表
 * @Author:       zc   
 * @CreateDate:   2018年10月29日 下午5:14:17   
 * @Version:      v1.0
 */
@Controller
@RequestMapping("daily")
public class ZcDailyController {

	@Resource
	private ZcDailyService zcDailyService;
	/**
	 * 进入质检日报表页面
	 * @return
	 */
	@RequestMapping("enterDailyPage")
	public String enterDailyPage(){
		return "zc/quality/daily";
	}
	/**
	 * 查找日报表
	 * @param request
	 * @param response
	 * @param zcQueryCriteria
	 */
	@RequestMapping("selectDailyByDate")
	public void selectDailyByDate(HttpServletRequest request,HttpServletResponse response,ZcQueryCriteria zcQueryCriteria){
		ZcDailyEntity zcDailyEntity = zcDailyService.selectDailyByDate(zcQueryCriteria);
		JSONObject json= JSONObject.fromObject(zcDailyEntity);  
		try {
			if(zcDailyEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找日报表(Android接口)
	 * @param request
	 * @param response
	 * @param zcQueryCriteria
	 */
	@RequestMapping("selectDailyByDateAndroid")
	public void selectDailyByDateAndroid(HttpServletRequest request,HttpServletResponse response,ZcQueryCriteria zcQueryCriteria){
		//keyword
		zcQueryCriteria.setKeyword("1");
		ZcDailyEntity zcDailyEntity = zcDailyService.selectDailyByDate(zcQueryCriteria);
		zcQueryCriteria.setKeyword("7");
		ZcDailyEntity zcDailyEntity2 = zcDailyService.selectDailyByDate(zcQueryCriteria);
		zcQueryCriteria.setKeyword("30");
		ZcDailyEntity zcDailyEntity3 = zcDailyService.selectDailyByDate(zcQueryCriteria);
		
	
		
		LqyDailyEntity lqyDailyEntity=new LqyDailyEntity();
		lqyDailyEntity.setelse(1, zcDailyEntity);
		lqyDailyEntity.setelse(2, zcDailyEntity2);
		lqyDailyEntity.setelse(3, zcDailyEntity3);
		
		JSONObject jsonObject=new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(lqyDailyEntity);
		
		if(lqyDailyEntity!=null) {
	        jsonObject.put("state", 1);
	        jsonObject.put("message", "成功");
	        jsonObject.put("data", jsonArray);
		}else {
	        jsonObject.put("state", 0);
	        jsonObject.put("message", "无数据");
	        jsonObject.put("data", jsonArray);
		}
        try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
